<!-- 表格 -->
<table class="layui-hide" id="classTable" lay-filter="test2"></table>
<!-- 表格工具 -->

<script>
    var roomData;
    function initClassTable() {
        layuiDate('.J-date');
        var table;
        // 请求路径
        var requireUrl = {
            classlist: "{:url('test/getclasslist')}",
        };

        layui.use('table', function () {
            table = layui.table;
            table.render({
                elem: '#classTable',
                url: requireUrl.classlist,
                toolbar: '#toolbarDemo',
                title: '考试课程',
                totalRow: false,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'id', title: '序号' },
                        { field: 'roomname', title: '课室' },
                        { field: 'capacity', title: '座位数' },
                        { field: 'test_capacity', title: '考试座位数' },
                    ],
                ],
                id: 'testReload',
                page: true,
                parseData: function (res) {
                    roomData = res
                    return {
                        code: 0,
                        msg: '',
                        count: res.length,
                        data: res,
                    };
                },
            });
        });

        // 搜索重置操作
        var active = {
            reload: function () {
                var queryParams = serializeObject($('.J-search-form'));
                console.log(queryParams);
                //执行重载
                table.reload(
                    'testReload',
                    {
                        page: {
                            curr: 1, //重新从第 1 页开始
                        },
                        where: queryParams,
                    },
                    'data'
                );
            },
        };
        $('.J-search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.J-reload').on('click', function () {
            $('.J-query-params').val('');
            form.render('select');
            active.reload ? active.reload.call(this) : '';
        });
    }
</script>
